home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Sets / BCSetD.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  6.2 KB  |  206 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  Restricted Rights Legend
  5. //  Use, duplication, or disclosure is subject to restrictions as set forth 
  6. //  in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer 
  7. //  Software clause at DFARS 252.227-7013. 
  8. //
  9. //  BCSetD.cpp
  10. //
  11. //  This file contains the definitions for the dynamic set.
  12.  
  13. #include "BCSetD.h"
  14.  
  15. template<class Item, BC_Index Buckets, class StorageManager>
  16. BC_TDynamicSet<Item, Buckets, StorageManager>::BC_TDynamicSet() {}
  17.  
  18. template<class Item, BC_Index Buckets, class StorageManager>
  19. BC_TDynamicSet<Item, Buckets, StorageManager>::
  20.   BC_TDynamicSet(BC_Index (*hash)(const Item&))
  21.     : fRep(hash) {}
  22.  
  23. template<class Item, BC_Index Buckets, class StorageManager>
  24. BC_TDynamicSet<Item, Buckets, StorageManager>::BC_TDynamicSet(BC_Index chunkSize)
  25. {
  26.   for (BC_Index index = 0; (index < Buckets); index++)
  27.     fRep.Bucket(index)->SetChunkSize(chunkSize);
  28. }
  29.  
  30. template<class Item, BC_Index Buckets, class StorageManager>
  31. BC_TDynamicSet<Item, Buckets, StorageManager>::
  32.   BC_TDynamicSet(const BC_TDynamicSet<Item, Buckets, StorageManager>& s)
  33.     : fRep(s.fRep) {}
  34.  
  35. template<class Item, BC_Index Buckets, class StorageManager>
  36. BC_TDynamicSet<Item, Buckets, StorageManager>::~BC_TDynamicSet() {}
  37.  
  38. template<class Item, BC_Index Buckets, class StorageManager>
  39. BC_TSet<Item>& BC_TDynamicSet<Item, Buckets, StorageManager>::
  40.   operator=(const BC_TSet<Item>& s)
  41. {
  42.   return BC_TSet<Item>::operator=(s);
  43. }
  44.  
  45. template<class Item, BC_Index Buckets, class StorageManager>
  46. BC_TSet<Item>& BC_TDynamicSet<Item, Buckets, StorageManager>::
  47.   operator=(const BC_TDynamicSet<Item, Buckets, StorageManager>& s)
  48. {
  49.   fRep = s.fRep;
  50.   return *this;
  51. }
  52.  
  53. template<class Item, BC_Index Buckets, class StorageManager>
  54. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::
  55.   operator==(const BC_TSet<Item>& s) const
  56. {
  57.   return BC_TSet<Item>::operator==(s);
  58. }
  59.  
  60. template<class Item, BC_Index Buckets, class StorageManager>
  61. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::
  62.   operator==(const BC_TDynamicSet<Item, Buckets, StorageManager>& s) const
  63. {
  64.   return (fRep == s.fRep);
  65. }
  66.  
  67. template<class Item, BC_Index Buckets, class StorageManager>
  68. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::
  69.   operator!=(const BC_TDynamicSet<Item, Buckets, StorageManager>& s) const
  70. {
  71.   return !operator==(s);
  72. }
  73.  
  74. template<class Item, BC_Index Buckets, class StorageManager>
  75. void BC_TDynamicSet<Item, Buckets, StorageManager>::
  76.   SetHashFunction(BC_Index (*hash)(const Item&))
  77. {
  78.   fRep.SetHashFunction(hash);
  79. }
  80.  
  81. template<class Item, BC_Index Buckets, class StorageManager>
  82. void BC_TDynamicSet<Item, Buckets, StorageManager>::
  83.   SetChunkSize(BC_Index chunkSize)
  84. {
  85.   for (BC_Index index = 0; (index < Buckets); index++)
  86.     fRep.Bucket(index)->SetChunkSize(chunkSize);
  87. }
  88.  
  89. template<class Item, BC_Index Buckets, class StorageManager>
  90. void BC_TDynamicSet<Item, Buckets, StorageManager>::Preallocate(BC_Index new_length)
  91. {
  92.   for (BC_Index index = 0; (index < Buckets); index++)
  93.     fRep.Bucket(index)->Preallocate(new_length);
  94. }
  95.  
  96. template<class Item, BC_Index Buckets, class StorageManager>
  97. void BC_TDynamicSet<Item, Buckets, StorageManager>::Clear()
  98. {
  99.   fRep.Clear();
  100. }
  101.  
  102. template<class Item, BC_Index Buckets, class StorageManager>
  103. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::Add(const Item& item)
  104. {
  105.   return fRep.Bind(item, 1);
  106. }
  107.  
  108. template<class Item, BC_Index Buckets, class StorageManager>
  109. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::Remove(const Item& item)
  110. {
  111.   return fRep.Unbind(item);
  112. }
  113.  
  114. template<class Item, BC_Index Buckets, class StorageManager>
  115. BC_Index BC_TDynamicSet<Item, Buckets, StorageManager>::ChunkSize() const
  116. {
  117.   return fRep.Bucket(0)->ChunkSize();
  118. }
  119.  
  120. template<class Item, BC_Index Buckets, class StorageManager>
  121. BC_Index BC_TDynamicSet<Item, Buckets, StorageManager>::Extent() const
  122. {
  123.   return fRep.Extent();
  124. }
  125.  
  126. template<class Item, BC_Index Buckets, class StorageManager>
  127. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::IsEmpty() const
  128. {
  129.   return (fRep.Extent() == 0);
  130. }
  131.  
  132. template<class Item, BC_Index Buckets, class StorageManager>
  133. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::
  134.   IsMember(const Item& item) const
  135. {
  136.   return fRep.IsBound(item);
  137. }
  138.  
  139. template<class Item, BC_Index Buckets, class StorageManager>
  140. void* BC_TDynamicSet<Item, Buckets, StorageManager>::operator new(size_t s)
  141. {
  142.   return StorageManager::Allocate(s);
  143. }
  144.  
  145. template<class Item, BC_Index Buckets, class StorageManager>
  146. void BC_TDynamicSet<Item, Buckets, StorageManager>::operator delete(void* p, size_t s)
  147. {
  148.   StorageManager::Deallocate(p, s);
  149. }
  150.  
  151. template<class Item, BC_Index Buckets, class StorageManager>
  152. void BC_TDynamicSet<Item, Buckets, StorageManager>::Purge() 
  153. {
  154.   fRep.Clear();
  155. }
  156.  
  157. template<class Item, BC_Index Buckets, class StorageManager>
  158. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::
  159.   Attach(const Item& item, const BC_Boolean& value)
  160. {
  161.   return BC_TSet<Item>::Attach(item, value);
  162. }
  163.  
  164. template<class Item, BC_Index Buckets, class StorageManager>
  165. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::Attach(const Item& item)
  166. {
  167.   return fRep.Bind(item, 1);
  168. }
  169.  
  170. template<class Item, BC_Index Buckets, class StorageManager>
  171. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::Detach(const Item& item)
  172. {
  173.   return fRep.Unbind(item);
  174. }
  175.  
  176. template<class Item, BC_Index Buckets, class StorageManager>
  177. BC_Index BC_TDynamicSet<Item, Buckets, StorageManager>::Cardinality() const
  178. {
  179.   return fRep.Extent();
  180. }
  181.  
  182. template<class Item, BC_Index Buckets, class StorageManager>
  183. BC_Index BC_TDynamicSet<Item, Buckets, StorageManager>::NumberOfBuckets() const
  184. {
  185.   return Buckets;
  186. }
  187.  
  188. template<class Item, BC_Index Buckets, class StorageManager>
  189. BC_Index BC_TDynamicSet<Item, Buckets, StorageManager>::Length(BC_Index bucket) const
  190. {
  191.   return fRep.Bucket(bucket)->Length();
  192. }
  193.  
  194. template<class Item, BC_Index Buckets, class StorageManager>
  195. BC_Boolean BC_TDynamicSet<Item, Buckets, StorageManager>::Exists(const Item& item) const
  196. {
  197.   return fRep.IsBound(item);
  198. }
  199.  
  200. template<class Item, BC_Index Buckets, class StorageManager>
  201. const Item& BC_TDynamicSet<Item, Buckets, StorageManager>::
  202.   ItemAt(BC_Index bucket, BC_Index index) const
  203. {
  204.   return (*fRep.Bucket(bucket))[index].fItem;
  205. }
  206.